import type { BingElements } from '../../../../../../../../types/constants/personalization/bing'
import { ThemeVarService } from '../../../../../../../../lib/abstract/style/theme_var/service'
import { PAGE_ELEMENTS, SUPPORTED_PLATFORMS } from '../../../../../../../../types/constants'
import { SearchCommonStyles } from '../../common'

export class BingAcademicPage {
  elements: BingElements = PAGE_ELEMENTS[SUPPORTED_PLATFORMS.BING]
  private static instance: BingAcademicPage
  private readonly themeVarService: ThemeVarService = ThemeVarService.getInstance()
  private readonly searchCommonStyles: SearchCommonStyles = SearchCommonStyles.getInstance()

  /**
   * 获取单例实例
   */
  public static getInstance(): BingAcademicPage {
    if (!BingAcademicPage.instance) {
      BingAcademicPage.instance = new BingAcademicPage()
    }
    return BingAcademicPage.instance
  }

  init(): void {
  }

  /**
   * 无搜索结果样式
   */
  noSearchResult(): string {
    return ``
  }

  getMainStyles(): string {
    return `
    #b_content {
      position: relative !important;
      padding: 0 0 20px 0 !important;
      
      .aca_topBar {
        position: absolute !important;
        right: 230px !important;
        top: 10px !important;
        
        .aca_top_items {
          left: unset !important;
        }
      }
      
      .aca_filterBar {
        position: absolute !important;
        right: 100px !important;
        top: 30px !important;
        
        .aca_fg_title {
          span {
            color: var(${this.themeVarService.search.default.text}) !important;
          }
        }
        
        .year_range {
          input {
            &#start_year, &#end_year {
              &:focus {
                outline: none !important;
              }
            }
          }
        }
      }

      /* 搜索结果列表 */
      #b_results {
        ${this.searchCommonStyles.resultContainerStyles()}
        margin-top: ${this.themeVarService.search.resultItem.gap} !important;
        
        > li {
          background-color: transparent !important;
          
          &.aca_algo_count {
            color: var(${this.themeVarService.search.default.text}) !important;
            text-align: right !important;
          }
          
          &:empty {
            display: none !important;
          }
        }
        
        /* 搜索结果项 */
        > li.aca_algo {
          ${this.searchCommonStyles.resultItemStyles()}
          
          /* 标题 */
          h2 {
            /* 去掉标题下划线 */
            a {
              color: var(${this.themeVarService.link.default.text}) !important;
              text-decoration: none !important;
              
              &:hover {
                text-decoration: none !important;
                color: var(${this.themeVarService.link.default.textHover}) !important;
              }
              
              strong {
                color: var(${this.themeVarService.em.text}) !important;
              }
            }
          }
          
          .aca_caption {
            .caption_abstract {
              color: var(${this.themeVarService.search.default.text}) !important;
              
              strong {
                color: var(${this.themeVarService.em.text}) !important;
              }
            }
          }
        }
      }
      
      #b_context:empty {
        display: none !important;
      }
      
      .aca_contact {
        background-color: transparent !important;
        text-align: center !important;
        padding: 0 !important;
        
        span {
          color: var(${this.themeVarService.search.default.text}) !important;
        }
      }
    }
    `
  }
}
